package cn.mesmile.order.config;

import org.springframework.context.annotation.Configuration;

/**
 * @author zb
 * @date 2020/12/18 10:32
 * @Description
 */
//@Configuration
public class DataSourceConfig {

//    @Bean
//    public SqlSessionFactory sqlSessionFactoryBean(DataSource dataSource) throws Exception {
//        // 订单服务中引入了mybatis-plus，所以要使用特殊的SqlSessionFactoryBean
//        MybatisSqlSessionFactoryBean sqlSessionFactoryBean = new MybatisSqlSessionFactoryBean();
//        // 代理数据源
//        sqlSessionFactoryBean.setDataSource(new DataSourceProxy(dataSource));
//        // 生成SqlSessionFactory
//        return sqlSessionFactoryBean.getObject();
//    }

//    @Bean
//    @ConfigurationProperties(prefix = "spring.datasource")
//    public DruidDataSource druidDataSource(){
//        return new DruidDataSource();
//    }

    /**
     *  将 DataSourceProxy 设置为主数据源，否则事务无法回滚
     * @param druidDataSource
     * @return
     */
//    @Primary
//    @Bean("dataSource")
//    @Primary
//    @Bean
//    public DataSourceProxy dataSource(DruidDataSource druidDataSource) {
//        return new DataSourceProxy(druidDataSource);
//    }

}
